package com.qvtu.management.controller;

import com.qvtu.management.pojo.Dept;
import com.qvtu.management.pojo.Result;
import com.qvtu.management.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list(){
        log.info("部门管理");

        List<Dept>  deptList = deptService.list();
        return Result.success(deptList);

    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除部门");
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add( @RequestBody Dept dept){
        log.info("添加部门：()",dept);
        deptService.add(dept);
        return Result.success();



    }
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        log.info("根据ID查询部门：{}", id);
        Dept dept = deptService.selectById(id);
        return Result.success(dept);
    }

    //修改部门
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("更新部门：{}", dept);
        deptService.update(dept);
        return Result.success();
    }




}
